var o = require("../../utils/api.js"), a = getApp();

Page({
    data: {
        info: "",
        num: 0,
        index: ""
    },
    onLoad: function(t) {
        var e = this;
        console.log(t), t.id && "" !== t.id && (e.setData({
            num: t.id
        }), o.Watir({
            id: t.id,
            openid: a.globalData.openid
        }).then(function(o) {
            if (console.log(o), 0 == o.errno) if (0 == o.data.length) wx.showToast({
                title: "没有查到该商品",
                icon: "none",
                duration: 2e3
            }); else {
                for (var a = [], t = 0; t < o.data.length; t++) o.data[t].checked = !1, a.push(o.data[t]);
                e.setData({
                    info: a
                });
            } else wx.showToast({
                title: o.message,
                icon: "none",
                duration: 2e3
            });
        })), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
    },
    code: function() {
        var t = this;
        wx.scanCode({
            onlyFromCamera: !0,
            success: function(e) {
                o.Watir({
                    id: e.result,
                    openid: a.globalData.openid
                }).then(function(o) {
                    console.log(o), 0 == o.errno ? (t.setData({
                        info: o.data
                    }), wx.showToast({
                        title: "扫码成功",
                        icon: "loading",
                        duration: 2e3
                    })) : wx.showToast({
                        title: o.message,
                        icon: "none",
                        duration: 2e3
                    });
                });
            }
        });
    },
    Input: function(o) {
        var a = o.detail.value;
        this.setData({
            num: a
        });
    },
    btn: function(t) {
        var e = this;
        if ("" == e.data.num || void 0 == e.data.num) return wx.showToast({
            title: "请输入核销码",
            icon: "loading",
            duration: 2e3
        }), !1;
        o.Watir({
            id: e.data.num,
            openid: a.globalData.openid
        }).then(function(o) {
            if (0 == o.errno) {
                for (var a = [], t = 0; t < o.data.length; t++) o.data[t].checked = !1, a.push(o.data[t]);
                e.setData({
                    info: a
                });
            } else wx.showToast({
                title: o.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    checkboxChange: function(o) {
        console.log("checkbox发生change事件，携带value值为：", o.detail.value);
        var a = this, t = a.data.info;
        console.log(a.data.info);
        for (var e = o.detail.value, n = [], i = 0; i < t.length; ++i) {
            t[i].checked = !1;
            for (var s = null, d = 0; d < e.length; ++d) if (t[i].go_id == e[d]) {
                t[i].checked = !0, s = {
                    id: t[i].go_id
                }, n.push(s);
                break;
            }
        }
        console.log(n), a.setData({
            index: n,
            info: a.data.info
        });
    },
    verification: function(t) {
        var e = this;
        console.log(e.data.index);
        var n = e.data.index;
        if ("" != n && void 0 != n) {
            for (var i = "", s = 0; s < n.length; s++) i += n[s].id + ",";
            console.log(i), o.Watirorders({
                id: i,
                openid: a.globalData.openid
            }).then(function(t) {
                console.log(t), 0 == t.errno ? (wx.showToast({
                    title: t.message,
                    icon: "none",
                    duration: 2e3
                }), o.Watir({
                    id: e.data.num,
                    openid: a.globalData.openid
                }).then(function(o) {
                    console.log(o), 0 == o.errno ? e.setData({
                        info: o.data
                    }) : (e.setData({
                        info: ""
                    }), wx.showToast({
                        title: o.message,
                        icon: "none",
                        duration: 2e3
                    }));
                })) : wx.showToast({
                    title: t.message,
                    icon: "none",
                    duration: 2e3
                });
            });
        } else wx.showToast({
            title: "请选择核销订单",
            icon: "loading",
            duration: 2e3
        });
    }
});